package recom;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

//import Controller.MainController;

import weka.Weka;

public class ModifiedRecom implements Runnable {

	public ModifiedRecom(String arff, String bugHit) {
		this.initArffFile = arff;
		this.bugHitMatriURL = bugHit;
	}

	private static final double UN_SELECT_SYMBOL = 0.0;

	// private MainController mainController = null;

	// private static Logger logger = Logger.getLogger(Recommendation.class
	// .getName());

	enum TYPE {
		ANP, AEP, ANF, AEF
	}

	// initial static numbers that will not change during the program
	// begin
	private int round = 9;

	private int funNumber = 0;

	private int numOfTotalCT = 0;

	// private int clussterIndex = 0;

	private double threshold = 1;

	// end

	// the number of fault-selected test case
	private int numOfFaultTC = 0;

	// the percentage of total test case that will be recommended to user
	private double percent = 0.1;

	private int SelectedTCThreshold = 0;

	private int numSelectedTC = 0;

	private String prefixOfClusterNum = "cluster";

	private String initArffFile = "./data/FlexProfile/binaryProfile/V2.arff";

	private String arffFile = "";

	private String tmpArffFile = "";

	private String bugHitMatriURL = "./data/flex bugHitMatrix/V2.txt";
	/**
	 * @Fields outputFile : 闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗閻╊喖缍�
	 */
	private String clusterResultFile = "E://clusterResult.txt";

	private String resultFile = "E://value.txt";
	// /**
	// * @Fields priority : 闁跨喐鏋婚幏鐑芥晸閺傘倖瀚瑰В蹇涙晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗闁跨喐鏋婚幏閿嬫綀閸婏拷
	// */
	// private List<Double> priority;

	/**
	 * @Fields clusterList : 闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归弬婊堟晸閿燂拷
	 */
	private List<List<Integer>> clusterList = new ArrayList<List<Integer>>();

	/**
	 * @Fields testCaseList : total testCase list
	 */
	private List<List<Double>> testCaseList = new ArrayList<List<Double>>();

	/**
	 * @Fields recmmendedTCList : recommended test case
	 */
	// List<List<Double>> recmmendedTCList = new ArrayList<List<Double>>();
	/**
	 * @Fields bugHitMatrixList :
	 *         闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔稿复閿斿吋瀚归柨鐔告灮閹风兘鏁撻弬銈嗗闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归懞妤呮晸鐟欙絽鍩岄柨鐔告灮閹风
	 *         ug闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐕傛嫹
	 */
	private List<String> bugHitMatrixList = new ArrayList<String>();

	/**
	 * @Fields confidenceOfFuncs :
	 *         濮ｅ繘鏁撻弬銈嗗闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹峰嘲绨查柨鐔告灮閹风onfidence閸婏拷
	 */
	private List<Double> confidenceOfFuncs = new ArrayList<Double>();

	/**
	 * @Fields valuesOfFunc : 闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹峰嘲缍嶅В蹇涙晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗
	 *         闁跨喐鏋婚幏绌塶p闁跨喐鏋婚幏锟絘ep闁跨喐鏋婚幏绌塶f闁跨喐鏋婚幏锟絘ef闁跨喐鏋婚幏宄帮拷
	 */
	private List<int[]> valuesOfFunc = new ArrayList<int[]>();

	/**
	 * @Fields clusterNumber : 闁跨喐鏋婚幏鐑筋湜闁跨喐鏋婚幏鐑芥晸閿燂拷
	 */
	private int clusterNumber = 50;
	/**
	 * @Fields suspiciousFuncList: 閸欘垳鏋掗崙鑺ユ殶閸掓銆�
	 */
	List<Integer> suspiciousFuncList = new ArrayList<Integer>();

	/**
	 * @Fields suspiciousnessOfTestCase: 濞村鐦悽銊ょ伐閻ㄥ嫬褰查悿鎴濓拷
	 */
	List<Double> suspiciousnessOfTestCase = new ArrayList<Double>();

	List<Double> weightsList = new ArrayList<Double>();

	List<Integer> indexOfSelectedCT = new ArrayList<Integer>();

	List<List<Double>> profile = new ArrayList<List<Double>>();

	// private boolean canGoOn = false;

	// public void addClusterIndex() {
	// clusterIndex++;
	//
	// }
	//
	// public int getClusterIndex() {
	// return clusterIndex;
	// }

	// public boolean isCanGoOn() {
	// return canGoOn;
	// }
	//
	// public void setCanGoOn(boolean canGoOn) {
	// this.canGoOn = canGoOn;
	// }

	// public ModifiedRecom(MainController controller) {
	// this.mainController = controller;
	// }

	// public double getConfidenceThreshold() {
	// return confidenceThreshold;
	// }
	//
	// public void setConfidenceThreshold(double confidenceThreshold) {
	// this.confidenceThreshold = confidenceThreshold;
	// }

	public List<List<Integer>> getClusterList() {
		return clusterList;
	}

	public int getClusterNumber() {
		return clusterNumber;
	}

	public void setClusterNumber(int clusterNumber) {
		this.clusterNumber = clusterNumber;
	}

	public boolean setArffFile(String fileUrl) {
		File file = new File(fileUrl);
		if (file.exists()) {
			initArffFile = fileUrl;
			return true;
		} else {
			return false;
		}
	}

	public int getNumFaultTC() {
		return numOfFaultTC;
	}

	public void setPercent(double percent) {
		this.percent = percent;
	}

	public String getResultFile() {
		return resultFile;
	}

	public void setResultFile(String resultFile) {
		this.resultFile = resultFile;
	}
	
	public void setRound(int round) {
		this.round = round;
	}
	
	@Override
	public void run() {
		readBugHitMatrix(bugHitMatriURL);
		int[] nums = calculateFunctionNumber();

		this.numOfFaultTC = 0;
		this.numOfTotalCT = 0;
		
		funNumber = nums[0];
		numOfTotalCT = nums[1];
		SelectedTCThreshold = (int) (percent * numOfTotalCT);
		tmpArffFile = getTempArffPath();

		int currentRound = 0;
		arffFile = initArffFile;
		while (currentRound < round) {
			initialize();
			cluster(arffFile);
			readClusterResult();
			iterator();
			deleteSelectedCT();
			calWeights();
			updateProfile();
			arffFile = createNewArffFile();
			currentRound++;
			System.out.println("Round " + currentRound + "\n\n\n");
		}
		String valFile = "E://values.txt"; 
		outputValue(valFile);
		output(resultFile);

		// delete the tmp arff file
		File tmp = new File(tmpArffFile);
		if (tmp.exists()) {
			tmp.delete();
		}

		// delete the cluster result file
		tmp = new File(clusterResultFile);
		if (tmp.exists()) {
			tmp.delete();
		}

		System.out.print("finish");
	}

	private void cluster(String arffFile) {
		Weka weka = new Weka(clusterNumber);
		weka.cluster(arffFile, clusterResultFile);
	}

	private void clear() {
		clusterList.clear();
		valuesOfFunc.clear();
		confidenceOfFuncs.clear();
		suspiciousFuncList.clear();
		suspiciousnessOfTestCase.clear();
		weightsList.clear();
		indexOfSelectedCT.clear();
		profile.clear();
	}

	private void initialize() {
		clear();

		this.numSelectedTC = 0;

		for (int i = 0; i < clusterNumber; i++) {
			clusterList.add(new ArrayList<Integer>());
		}

		for (int i = 0; i < funNumber; i++) {
			int[] defaultValues = { 0, 0, 0, 0 };
			valuesOfFunc.add(defaultValues);
		}

		for (int i = 0; i < funNumber; i++) {
			confidenceOfFuncs.add(0.0);
		}

		for (int j = 0; j < funNumber; j++) {
			suspiciousFuncList.add(j);
		}
		// System.out.println("ssuspiciousFuncList" + suspiciousFuncList);
		// System.out.println(suspiciousFuncList.get(9));
	}

	private int[] calculateFunctionNumber() {
		int[] numbers = { 0, 0 };
		try {
			BufferedReader bfReader = new BufferedReader(new FileReader(
					new File(initArffFile)));
			String data = null;
			while ((data = bfReader.readLine()) != null) {
				if (data.startsWith("@attribute func")) {
					// means function area
					numbers[0]++;
				} else if (data.startsWith("@data")) {
					// means data area begins
					break;
				}
			}

			while ((data = bfReader.readLine()) != null) {
				numbers[1]++;
				String[] metaDatas = data.substring(0, data.length())
						.split(",");
				List<Double> testCase = new ArrayList<Double>();
				for (String metaData : metaDatas) {
					double value = Double.parseDouble(metaData);
					testCase.add(value);
				}
				testCaseList.add(testCase);
			}

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return numbers;
	}

	/**
	 * @Title: readData
	 * @Description: 闁跨喐鏋婚幏宄板絿arff闁跨喍鑼庣涵閿嬪闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹烽攱鐦￠柨鐔告灮閹风兘鏁撻弬銈嗗
	 *               闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗
	 *               闁跨喐鏋婚幏鐑芥晸閹恒儻璁ｉ幏鐑芥晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗
	 * @param dataFile
	 *            arff闁跨喍鑼庣涵閿嬪
	 * @return void
	 * @throws
	 */
	private boolean readClusterResult() {
		boolean result = false;
		try {
			BufferedReader bfReader = new BufferedReader(new FileReader(
					new File(clusterResultFile)));
			String data = null;
			int indexOfTestcase = 0;
			while ((data = bfReader.readLine()) != null) {
				if (data.startsWith("@") || data.equals("")) {
					continue;
				}
				int clusterNum = Integer.parseInt(data.substring(data
						.indexOf(prefixOfClusterNum)
						+ prefixOfClusterNum.length()));

				List<Integer> cluster = clusterList.get(clusterNum);
				cluster.add(indexOfTestcase);
				indexOfTestcase += 1;
				suspiciousnessOfTestCase.add(0.0);
				result = true;
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}

	private void readBugHitMatrix(String dataFile) {
		try {
			BufferedReader bfReader = new BufferedReader(new FileReader(
					new File(dataFile)));
			String data = null;
			while ((data = bfReader.readLine()) != null) {
				data = data.replaceAll(",", "");
				bugHitMatrixList.add(data);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void iterator() {
		// System.out.println(suspiciousnessOfTestCase);
		// System.out.println(suspiciousFuncList);
		for (int i = 0; i < clusterNumber; i++) {
			List<Integer> cluster = clusterList.get(i);
			System.out.println("cluster " + i + "before remove");
			System.out.println(cluster);
			do {
				if (!(numSelectedTC < SelectedTCThreshold)) {
					return;
				}

				int index = selectTheMostSuspiciousCase(cluster);

				if (-1 != index) {
					int indexOfTestCase = cluster.get(index);
					System.out.println("recommend: " + indexOfTestCase);
					List<Double> testCase = testCaseList.get(indexOfTestCase);
					// System.out.println("recommend: " + testCase);
					// List<List<Double>> recommendedTCList = new
					// ArrayList<List<Double>>();
					// recommendedTCList.add(testCase);
					//
					// List<TestCase> testCaseList = new ArrayList<TestCase>();
					// TestCase tc = new TestCase(indexOfTestCase);
					// testCaseList.add(tc);
					// mainController.showRecommendTestCase(testCaseList);
					String bugHitMatrix = bugHitMatrixList.get(indexOfTestCase);

					boolean failure = checkTestcaseResult(bugHitMatrix);
					//
					// while(true) {
					// if(!canGoOn) {
					// try {
					// Thread.sleep(1);
					// } catch (InterruptedException e) {
					// e.printStackTrace();
					// }
					// }else {
					// canGoOn = false;
					// break;
					// }
					// }
					// List<Integer> successList =
					// mainController.getResultsOfTestCases();

					// List<Boolean> resultList = new ArrayList<Boolean>();

					// for (int tmpI = 0; tmpI < testCaseList.size(); tmpI++) {
					// if (successList.contains(tmpI)) {
					// resultList.add(true);
					// } else {
					// resultList.add(false);
					// }
					// }
					// boolean failure = resultList.get(0);

					numSelectedTC++;

					if (true == failure) {
						numOfFaultTC++;
					}

					accumulate(testCase, failure);
					updateConfidenceOfFuncs(testCase, failure);

					cluster.remove(index);
					indexOfSelectedCT.add(indexOfTestCase);
					System.out.println("cluster " + i + "after remove");
					System.out.println(cluster);
				}
			} while (hasSuspiciousTestCase(cluster));
		}
	}

	// private void recommend(int cIndex) {
	// if (cIndex < clusterNumber) {
	// List<Integer> cluster = clusterList.get(cIndex);
	// System.out.println("cluster " + cIndex + "before remove");
	// System.out.println(cluster);
	//
	// int index = selectTheMostSuspiciousCase(cluster);
	//
	// if (-1 != index) {
	// int indexOfTestCase = cluster.get(index);
	// System.out.println("recommend: " + indexOfTestCase);
	// List<Double> testCase = testCaseList.get(indexOfTestCase);
	// // System.out.println("recommend: " + testCase);
	// recmmendedTCList.add(testCase);
	//
	// List<TestCase> testCaseList = new ArrayList<TestCase>();
	// TestCase tc = new TestCase(indexOfTestCase);
	// testCaseList.add(tc);
	// mainController.showRecommendTestCase(testCaseList);
	//
	// cluster.remove(index);
	// System.out.println("cluster " + cIndex + "after remove");
	// System.out.println(cluster);
	// }
	// }
	// }
	//
	// public void updateTestCasesResult() {
	// List<Integer> successList = mainController.getResultsOfTestCases();
	//
	// List<Boolean> resultList = new ArrayList<Boolean>();
	//
	// for (int tmpI = 0; tmpI < testCaseList.size(); tmpI++) {
	// if (successList.contains(tmpI)) {
	// resultList.add(true);
	// } else {
	// resultList.add(false);
	// }
	// }
	// boolean failure = resultList.get(0);
	//
	// List<Double> testCase = recmmendedTCList.get(0);
	// accumulate(testCase, failure);
	// updateConfidenceOfFuncs(testCase, failure);
	//
	// if(hasSuspiciousTestCase(clusterList.get(clusterIndex))) {
	// recommend(clusterIndex);
	// }else {
	// recommend(clusterIndex++);
	// }
	// }

	public boolean hasSuspiciousTestCase(List<Integer> l) {
		for (int i : l) {
			if (suspiciousnessOfTestCase.get(i) > 0) {
				return true;
			}
		}
		return false;
	}

	public boolean checkTestcaseResult(String bugHitMatrix) {
		boolean failure = bugHitMatrix.contains("1");
		return failure;
	}

	public void updateConfidenceOfFuncs(List<Double> testCase, boolean failure) {
		suspiciousFuncList.removeAll(suspiciousFuncList);
		// System.out.println(suspiciousFuncList);
		int value = 0;
		if (failure) {
			value = -1;
		} else {
			value = 1;
		}

		// update confidence of functions
		for (int i = 0; i < testCase.size(); i++) {
			double select = testCase.get(i);
			if (UN_SELECT_SYMBOL != select) {
				double confidence = confidenceOfFuncs.get(i) + value;
				confidenceOfFuncs.set(i, confidence);
			}
		}

		// construct suspicious function list
		for (int i = 0; i < confidenceOfFuncs.size(); i++) {
			Double confidence = confidenceOfFuncs.get(i);
			if (confidence < threshold) {
				suspiciousFuncList.add(i);
			}
		}
		// System.out.println(suspiciousFuncList);
		// System.out.println("suspicious function");
		// for (int i : suspiciousFuncList) {
		// System.out.print(i + ",");
		// }

	}

	// construct suspicious function list

	public void accumulate(List<Double> testCase, boolean failure) {
		int length = testCase.size();
		int v = 0;
		int[] values;
		double c;
		for (int i = 0; i < length; i++) {
			c = testCase.get(i);
			values = valuesOfFunc.get(i);
			if (failure && UN_SELECT_SYMBOL != c) {
				v = TYPE.AEF.ordinal();
			} else if (failure && UN_SELECT_SYMBOL == c) {
				v = TYPE.ANF.ordinal();
			} else if (!failure && UN_SELECT_SYMBOL != c) {
				v = TYPE.AEP.ordinal();
			} else if (!failure && UN_SELECT_SYMBOL == c) {
				v = TYPE.ANP.ordinal();
			}
			values[v] += 1;
		}
	}

	// private boolean isFinish(int indexOfCluster) {
	// boolean allSurpassCT = true;
	// Iterator<Double> it = suspicionOfFunctions.iterator();
	// while(it.hasNext()) {
	// Double sus = (Double)it.next();
	// if(sus < confidenceThreshold) {
	// allSurpassCT = false;
	// break;
	// }
	// }
	// return false;
	// }
	/**
	 * @Title: selectTheMostSuspiciousCase
	 * @Description: 闁跨喐鏋婚幏鐑斤拷闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗閺嶏繝鏁撻弬銈嗗闁跨喐鏋婚幏鐑芥晸鐞涙顣
	 *               幏鐑芥晸閺傘倖瀚归悧鐔兼晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗闁跨噦鎷�
	 * @param 闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨锟
	 *            � * 閿燂拷
	 * @return int
	 *         闁跨喐鏋婚幏鐑斤拷闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔惰寧鐠囇勫闁跨喐鏋婚幏鐑芥晸閺傘倖瀚归柨鐔告灮閹风兘鏁撻弬銈嗗閸椼倝鏁撻敓锟
	 *         � * @throws
	 */

	public int selectTheMostSuspiciousCase(List<Integer> TestcaseList) {

		// System.out.println();
		if (null == TestcaseList || TestcaseList.size() == 0) {
			return -1;
		}

		double suspiciousness = 0;
		int indexOfMostSuspiciousCase = 0;

		int currentIndex = 0;
		Iterator<Integer> it = TestcaseList.iterator();
		while (it.hasNext()) {
			int indexOfTestCase = (Integer) it.next();
			// System.out.println("indexofTestCase" + indexOfTestCase);

			List<Double> testCase = testCaseList.get(indexOfTestCase);
			// System.out.println("suspiciousFuncList" + suspiciousFuncList);
			double confidence = getConfidenceOfTestCase(testCase,
					suspiciousFuncList);
			suspiciousnessOfTestCase.set(indexOfTestCase, confidence);
			// System.out.println("confidence" + confidence);

			if (confidence > suspiciousness) {
				suspiciousness = confidence;
				indexOfMostSuspiciousCase = currentIndex;
			}
			currentIndex++;
		}
		// System.out.println("suspiciousness" + suspiciousnessOfTestCase);
		// int count = 0;
		/*
		 * for(double d: suspiciousnessOfTestCase){ if(d != 0.0){ count++; }
		 * System.out.println("count" + count);
		 * 
		 * }
		 */
		System.out.println("indexOfMostSuspiciousCase "
				+ indexOfMostSuspiciousCase);
		return indexOfMostSuspiciousCase;
	}

	private double getConfidenceOfTestCase(List<Double> testCase,
			List<Integer> confidences) {
		// System.out.println("testCase" + testCase);
		/*
		 * if (testCase.length() != confidences.size()) { return 0; }
		 */

		double confidence = 0;
		int length = testCase.size();
		for (int i = 0; i < length; i++) {
			double select = testCase.get(i);
			if (UN_SELECT_SYMBOL != select) {
				if (confidences.contains(i)) {
					confidence++;
				}
			}
		}

		// System.out.println("confidence " + confidence);
		return confidence;
	}

	private void outputValue(String filename) {
		try {
			PrintWriter writer = new PrintWriter(new FileWriter(filename));
			writer.println("TC\tAEP\tAEF\tANP\tANF");
			for (int i = 0; i < valuesOfFunc.size(); i++) {
				int[] values = valuesOfFunc.get(i);
				writer.println(i + "\t" + values[TYPE.AEP.ordinal()] + "\t"
						+ values[TYPE.AEF.ordinal()] + "\t"
						+ values[TYPE.ANP.ordinal()] + "\t"
						+ values[TYPE.ANF.ordinal()]);
			}
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void deleteSelectedCT() {
		List<List<Double>> remainTC = new ArrayList<List<Double>>();
		List<String> remainBH = new ArrayList<String>();

		for (int i = 0; i < testCaseList.size(); i++) {
			if (!indexOfSelectedCT.contains(i)) {
				remainTC.add(testCaseList.get(i));
				remainBH.add(bugHitMatrixList.get(i));
			}
		}

		testCaseList.clear();
		bugHitMatrixList.clear();

		testCaseList = remainTC;
		bugHitMatrixList = remainBH;
	}

	private void calWeights() {
		weightsList.clear();
		for (int i = 0; i < funNumber; i++) {
			int[] values = valuesOfFunc.get(i);
			int aep = values[TYPE.AEP.ordinal()];
			int aef = values[TYPE.AEF.ordinal()];
			int anf = values[TYPE.ANF.ordinal()];
			double weight = (double)aef / (aef + anf + aep);
			weightsList.add(weight);
		}
	}

	private void updateProfile() {
		for (int i = 0; i < testCaseList.size(); i++) {
			List<Double> tc = testCaseList.get(i);
			List<Double> p = new ArrayList<Double>();
			for (int j = 0; j < tc.size(); j++) {
				p.add(tc.get(j) * weightsList.get(j));
			}
			profile.add(p);
		}
	}

	private String createNewArffFile() {
		try {
			File tmpFile = new File(tmpArffFile);

			if (!tmpFile.exists() && !tmpFile.createNewFile()) {
				return "";
			}
			PrintWriter pw = new PrintWriter(tmpFile);

			pw.println("@relation BinaryProfile");

			for (int i = 0; i < funNumber; i++) {
				pw.println("@attribute func" + (i + 1) + " Numeric");
			}

			pw.println();

			pw.println("@data");

			for (int i = 0; i < profile.size(); i++) {
				List<Double> p = profile.get(i);

				pw.print(p.get(0));
				for (int j = 1; j < p.size(); j++) {
					pw.print("," + p.get(j));
				}
				pw.println();
			}

			pw.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return tmpArffFile;
	}

	private void output(String filename) {
		try {
			PrintWriter writer = new PrintWriter(new FileWriter(filename));
			writer.println("PERCENT\tFALUT_NUM\tTOTAL_NUM");
			writer.print(percent + "\t" + numOfFaultTC + "\t" + (SelectedTCThreshold * 9));
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String getTempArffPath() {
		Random r = new Random();
		int randomInt = r.nextInt();
		Calendar cal = Calendar.getInstance();
		return cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-"
				+ cal.get(Calendar.DATE) + "-" + cal.get(Calendar.HOUR) + "-"
				+ cal.get(Calendar.MINUTE) + "-" + cal.get(Calendar.SECOND)
				+ "-" + cal.get(Calendar.MILLISECOND) + randomInt + ".arff";
	}

	public static void main(String[] args) {
		ModifiedRecom modRecom = new ModifiedRecom(
				"./data/FlexProfile/binaryProfile/V2.arff",
				"./data/flex bugHitMatrix/V2.txt");
		modRecom.setRound(9);
		modRecom.setResultFile("10per.txt");
		modRecom.setPercent(0.1);
		modRecom.run();
		modRecom.setRound(4);
		modRecom.setResultFile("20per.txt");
		modRecom.setPercent(0.2);
		modRecom.run();
		modRecom.setRound(3);
		modRecom.setResultFile("25per.txt");
		modRecom.setPercent(0.25);
		modRecom.run();
		modRecom.setRound(3);
		modRecom.setResultFile("30per.txt");
		modRecom.setPercent(0.3);
		modRecom.run();
		modRecom.setRound(1);
		modRecom.setResultFile("50per.txt");
		modRecom.setPercent(0.5);
		modRecom.run();
	}
}
